﻿@using Jqpress.Framework.Mvc
@using Jqpress.Framework.Web;
@model Jqpress.Web.Areas.Admin.Models.PostModel
@{
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";   
    ViewBag.Title = Model.Post.PostId > 0 ? "修改文章 - 管理中心 - Powered by Jqpress" : "添加文章 - 管理中心 - Powered by Jqpress";
}


 

<style type="text/css">
/*tag choose*/
.selected {background:#c00; color:#fff;}

</style>

<!-- TinyMCE -->
<script type="text/javascript" src="/common/editors/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
    tinyMCE.init({
        // General options
        mode: "exact",
        elements: "PostContent",
        theme: "advanced",
        language: "zh-cn",

        plugins: "autolink,lists,spellchecker,style,save,advhr,advimage,advlink,emotions,inlinepopups,insertdatetime,searchreplace,contextmenu,paste,fullscreen,xhtmlxtras,insertcode", //autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,insertcode
        // Theme options
        theme_advanced_buttons1: "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect,insertcode",
        theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,|,insertdate,inserttime,|,forecolor,backcolor,insertcode|,fullscreen",
        theme_advanced_buttons3: "", //tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen
        theme_advanced_buttons4: "", //insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,blockquote,pagebreak,|,insertfile,imagemanager,insertcode
        theme_advanced_toolbar_location: "top",
        theme_advanced_toolbar_align: "left",
        theme_advanced_statusbar_location: "bottom",
        theme_advanced_resizing: true,


        // Example content CSS (should be your site CSS)
        content_css: "/common/editors/css/content.css",

        // Drop lists for link/image/media/template dialogs
        template_external_list_url: "/common/editors/lists/template_list.js",
        external_link_list_url: "/common/editors/lists/link_list.js",
        external_image_list_url: "/common/editors/lists/image_list.js",
        media_external_list_url: "/common/editors/lists/media_list.js",

        // Style formats
        style_formats: [
			{ title: 'Bold text', inline: 'b' },
			{ title: 'Red text', inline: 'span', styles: { color: '#ff0000'} },
			{ title: 'Red header', block: 'h1', styles: { color: '#ff0000'} },
			{ title: 'Example 1', inline: 'span', classes: 'example1' },
			{ title: 'Example 2', inline: 'span', classes: 'example2' },
			{ title: 'Table styles' },
			{ title: 'Table row 1', selector: 'tr', classes: 'tablerow1' }
		],

        // Replace values for the template plugin
        template_replace_values: {
            username: "Some User",
            staffid: "991234"
        }
    });
</script>
<!-- /TinyMCE -->
<script type="text/javascript">

    function addFileToEditor(fileUrl, fileExtension) {

        var fileExtension = fileExtension.toLowerCase();
        if (fileExtension == '.gif' || fileExtension == '.jpg' || fileExtension == '.jpeg' || fileExtension == '.bmp' || fileExtension == '.png') {
            var imageTag = "<img src=\"" + fileUrl + "\"/>";
            tinyMCE.execCommand('mceInsertContent', false, imageTag);

        } else {
            var imageTag = "<a href=\"" + fileUrl + "\">" + fileUrl + "</a>";
            tinyMCE.execCommand('mceInsertContent', false, imageTag);
        }

    }

    function createSummary(type) {
        var postContent = tinyMCE.activeEditor.getContent();
        var postSummary = $("#Summary");

         if (type == 'full') {
             postSummary.text(postContent);
         }
         else {
             postSummary.text(postContent.replace(/<[^>]+>/g, "").substring(0, 300));
         }
        return false;
    }
</script>
<script type="text/javascript">
    function checkForm() {
        var title = $("#Title");
        var content = $("#PostContent");

        if (title.text() == "") {
            //$("#lableTitle").css("color","red");
            //return false;
        }
        if (content.text() == "") {
            // return false;
        }
    }
</script>


<!-- BEGIN PAGE HEADER-->
<div class="row">
<div class="col-md-12">
    <!-- BEGIN PAGE TITLE & BREADCRUMB-->
    <h3 class="page-title">
        @(Model.Post.PostId > 0 ? "编辑" : "添加")文章 
    </h3>
    <!-- END PAGE TITLE & BREADCRUMB-->
</div>
</div>
<!-- END PAGE HEADER-->



 @Html.JPartial("_Notifications")


<div class="portlet-body form">
    <form name="form1" method="post" action="@Url.Action("SavePost", "Post")" enctype="multipart/form-data" >
    <input type="hidden"  id="PostId" name="PostId" value="@Model.Post.PostId" />

    <div class="form-body">
                           
        <div class="form-group">
            <label for="Title">标题：&nbsp;</label>
            <input type="text" id="Title" name="Title" value="@Model.Post.Title" class="form-control" style="width:30%;" />
        </div>

        <div class="form-group">
            <label for="CategoryId">分类：&nbsp;</label>
            @Html.DropDownList("CategoryId", Model.CateSelectItem, new { @class = "form-control input-medium" })
        </div>


        <div class="form-group">
            <label  class="control-label" for="TitlePic">缩略图:</label> 
            <div class=""> 
            <input type="file" id="TitlePic" name="TitlePic" value="@Model.Post.TitlePic"   onchange="checkSize(this)" />

            @if(!string.IsNullOrEmpty(Model.Post.TitlePic))
            {
                <img src="@Model.Post.TitlePic"  style="border:0px; width:120px; height:90px;"  />                                
            }
            </div>
        </div>

        <div class="form-group">
         <div class="col-md-4">
            <a href="#filemodal" title="插入图片/文件"  data-toggle="modal" >插入图片/文件</a>
            </div>
            <textarea name="PostContent" rows="2" cols="20" id="PostContent" style="height:400px;width:95%;">@Model.Post.PostContent</textarea>
        </div>
                         

        <div class="form-group">

        <label for="CategoryId">首页显示</label>
          @if(Model.Post.HomeStatus ==1){
              <input type="checkbox" name="HomeStatus" id="HomeStatus"  value="1" checked="checked" />
          } else{
              <input type="checkbox" name="HomeStatus" id="HomeStatus"  value="1" />          
          }
          &nbsp;&nbsp;

          <label for="CategoryId">推荐</label>
          @if(Model.Post.Recommend ==1){
              <input type="checkbox" name="Recommend" id="Recommend"  value="1"  checked="checked" />
          } else{
              <input type="checkbox" name="Recommend" id="Recommend"  value="1"  />          
          }
        </div>

        <div class="form-group">
            <button type="submit" name="btnEdit"  onclick="return checkForm();" id="btnEdit" class="btn btn-primary" >@(Model.Post.PostId > 0 ? "修改" : "发布")</button>
            <button type="button" class="btn btn-default" onclick="history.go(-1)" >返回 </button>
        </div>


    </div>
                        
    </form>

    <div id="filemodal" class="modal fade" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog" style="width:80%!important; height:90% !important">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" id="file-close" class="close" data-dismiss="modal" aria-hidden="true"></button>
            </div>
            <div class="modal-body">
                <div class="scroller" style="height:500px; width:100%" data-always-visible="1" data-rail-visible1="1">
                <iframe  height="80%" id="ifrmfile" name="ifrmfile" src="/admin/files/list" frameBorder="0" width="99.6%"></iframe> 
                </div>
            </div>
                             
        </div>
    </div>
    </div>

</div>
<script type="text/javascript">
    function modalClose() {
        $("#file-close").click();
    }

    function checkSize(file) {
        var size = file.files[0].size / 1024;
        if (size > 1000) {
            alert("图片大小不能超过1M");
            $(file).val("");
        }
    }
</script>

